import type { HourDataType, MsgObj, RealTimeParkingRecord } from '../types.d';

export const handleHourData = (data: HourDataType[]) => {
  const traffic: number[] = new Array(24).fill(0);
  const charged: number[] = new Array(24).fill(0);
  const actual: number[] = new Array(24).fill(0);
  const payable: number[] = new Array(24).fill(0);
  const except: number[] = new Array(24).fill(0);
  data.forEach((item) => {
    traffic[item.recordHour] = item.parkingTraffic;
    charged[item.recordHour] = item.chargedOrder;
    actual[item.recordHour] = Math.round(item.actualAmount / 100);
    payable[item.recordHour] = Math.round(item.payableAmount / 100);
    except[item.exceptOrder] = item.exceptOrder;
  });
  return {
    traffic,
    charged,
    actual,
    payable,
    except,
  };
};

export const handleRealTimeMsg = (data: RealTimeParkingRecord[]): MsgObj[] =>
  data.map((item) => ({
    spotId: item.spotId,
    parkingLotName: item.parkingLotName,
    time: item.outTime || item.inTime,
    plateNumber: item.plateNumber,
    type: item.outTime ? 'out' : 'in',
  }));
